
class Person {
    //成员变量
    private String name;
    private int age;   //private这个关键字表示只能在当前类中访问 name 和 age

    //利用构造方法来实现成员属性的初始化
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    //公开的接口
    public void getName(String name) {
        this.name = name;
    }

    public void setName(String name) {
        this.name = name;
    }
    //编辑器自动生成的
    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //成员方法
    public void show() {
        System.out.println(name + " " + age);
    }
}
public class Test {
    public static void main(String[] args) {
        Person person = new Person("zhangsan",18);
        //person.name = "zhangsan";    //由于是private关键字修饰的 ，所以不能访问
        //应该利用setName接口来访问
        //person.getName("zhangsan");
        person.setName("wang") ;
        person.show();
    }
}
